package com.ylyq.ylxx.intercepter;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.charset.Charset;

@Configuration
public class   AuthConfig implements WebMvcConfigurer {
    @Bean
    public AuthIntercepter authIntercepter() {
        return new AuthIntercepter();
    }
    @Bean
    public OceanengineAuthIntercepter oceanengineAuthIntercepter() {
        return new OceanengineAuthIntercepter();
    }
    @Bean
    public JinritemaiAuthIntercepter jinritemaiAuthIntercepter() {
        return new JinritemaiAuthIntercepter();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration addInterceptor = registry.addInterceptor(authIntercepter());

        // 排除配置
        addInterceptor.excludePathPatterns("/error");
        addInterceptor.excludePathPatterns("/static/**");
        addInterceptor.excludePathPatterns("/upload/**");
        addInterceptor.excludePathPatterns("/sysUser/login**");
        addInterceptor.excludePathPatterns("/sysUser/register**");
        addInterceptor.excludePathPatterns("/test/**");
        addInterceptor.excludePathPatterns("/chat/**");
        addInterceptor.excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**","/swagger-ui.html");
        addInterceptor.excludePathPatterns("/file/**");
//        addInterceptor.excludePathPatterns("/lingo/**");
        addInterceptor.excludePathPatterns("/core/**");
        addInterceptor.excludePathPatterns("/cover/getCoverDetails");
        // 拦截配置
        addInterceptor.excludePathPatterns("/oAuth/oAuthCallback");

        //巨量拦截
        registry.addInterceptor(oceanengineAuthIntercepter()).addPathPatterns("/oCeanengine/**").addPathPatterns("/ylyqRefusePlan/**").addPathPatterns("/Jinritemai/**");
//        registry.addInterceptor(jinritemaiAuthIntercepter()).addPathPatterns("/Jinritemai/**");
    }

    /**
     * 设置乱码处理
     * @return
     */
    @Bean
    public HttpMessageConverter<String> responseBodyConverter() {
        return new StringHttpMessageConverter(Charset.forName("UTF-8"));
    }


}
